package com.jjb.www.ui.fragment;

import android.os.Bundle;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.app.AppFragment;
import com.jjb.www.http.api.LiveDingApi;
import com.jjb.www.http.api.OnDemandRecordingApi;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpListData;
import com.jjb.www.ui.activity.CopyActivity;
import com.jjb.www.ui.activity.DryRrunActivity;
import com.jjb.www.ui.activity.VerificationRecordActivity;
import com.jjb.www.ui.adapter.OnDemandAdapter;
import com.jjb.www.widget.CommonRefreshView;

import java.util.List;

import okhttp3.Call;

/**
 *    author : Android CRG
 *    time   : 2018/10/18on demand
 *    desc   : 点播课程校验记录
 */
public final class OnDemandRecordingFragment extends AppFragment<VerificationRecordActivity> {
    private OnDemandAdapter mAdapter;
//    private CommonRefreshView mRefreshView;
private WrapRecyclerView mRvList;
    private static final String INTENT_KEY_ID_CARD = "id_card";
    private static final String INTENT_KEY_PLANCODE = "planCode";
    private static final String INTENT_KEY_POSTCODE = "trainPostCode";
    private static final String INTENT_KEY_TYPE = "type";
    public static OnDemandRecordingFragment newInstance(String id_card,String planCode,String trainPostCode,String type) {
        OnDemandRecordingFragment fragment = new OnDemandRecordingFragment();
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY_ID_CARD, id_card);
        bundle.putString(INTENT_KEY_PLANCODE, planCode);
        bundle.putString(INTENT_KEY_POSTCODE, trainPostCode);
        bundle.putString(INTENT_KEY_TYPE, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_recording;
    }

    @Override
    protected void initView() {
        mRvList = findViewById(R.id.rv_list);
        mAdapter = new OnDemandAdapter(getContext());
    }

    @Override
    protected void initData() {

        EasyHttp.get(this)
                .api(new OnDemandRecordingApi()
                        .setId_card(getString(INTENT_KEY_ID_CARD))
                        .setType(getString(INTENT_KEY_TYPE))
                        .setPlanCode(getString(INTENT_KEY_PLANCODE))
                        .setTrainPostCode(getString(INTENT_KEY_POSTCODE))
                        .setPage(1)
                        .setPageSize(100))
                .request(new HttpCallback<HttpData<OnDemandRecordingApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<OnDemandRecordingApi.Bean> data) {
                        mAdapter.setData(data.getData().getData());
                    }
                });
//        mRefreshView.setDataHelper(new CommonRefreshView.DataHelper<OnDemandRecordingApi.Bean>() {
//            @Override
//            public AppAdapter<OnDemandRecordingApi.Bean> getAdapter() {
//                return mAdapter;
//            }
//
//            @Override
//            public void loadData(int p, HttpCallback<HttpListData<OnDemandRecordingApi.Bean>> callback) {
//                EasyHttp.get(getViewLifecycleOwner())
//                        .api(new OnDemandRecordingApi()
//                                .setId_card(getString(INTENT_KEY_ID_CARD))
//                                .setType(getString(INTENT_KEY_TYPE))
//                                .setPlanCode(getString(INTENT_KEY_PLANCODE))
//                                .setTrainPostCode(getString(INTENT_KEY_POSTCODE))
//                                .setPage(p)
//                                .setPageSize(100)
//                        ).request(new HttpCallback<HttpListData<OnDemandRecordingApi.Bean>>(getAttachActivity()) {
//
//                    @Override
//                    public void onStart(Call call) {
//
//                    }
//
//                    @Override
//                    public void onSucceed(HttpListData<OnDemandRecordingApi.Bean> result) {
//                        callback.onSucceed(result);
//                    }
//
//                    @Override
//                    public void onFail(Exception e) {
//                        super.onFail(e);
//                        callback.onFail(e);
//                    }
//
//                    @Override
//                    public void onEnd(Call call) {
//                        super.onEnd(call);
//                        callback.onEnd(call);
//                    }
//                });
//            }
//
//            @Override
//            public void onRefreshSuccess(List<OnDemandRecordingApi.Bean> list, int listCount) {
//
//            }
//
//            @Override
//            public void onRefreshFailure() {
//
//            }
//
//            @Override
//            public void onLoadMoreSuccess(List<OnDemandRecordingApi.Bean> loadItemList, int loadItemCount) {
//
//            }
//
//            @Override
//            public void onLoadMoreFailure() {
//
//            }
//        });
//        mRefreshView.initData();
    }
}